﻿@model Epi.Web.MVC.Models.UserResetPasswordModel
@{
    ViewBag.Title = "Epi Info™ Web Enter - Create New Password";
   
}
<script type="text/javascript">
    $(document).ready(function () {
        $("#ResetButton").click(function (e) {
            e.preventDefault();
             var password = $("#password").val();
              var cpassword = $("#password_confirm").val();
            if (password.toString() == cpassword.toString()) {

                 if(ValidatePassword())
                        {
                            $("#errMsgPwdCriteria").hide();
                            $('#myform').submit();

                        }
                        else {
                           $("#errMsgPwdCriteria").show();
                           $("#errMsgPwdNoMatch").hide();
                        }
           }
            else {
                $("#errMsgPwdNoMatch").show();
                $("#errMsgPwdCriteria").hide();
            }
           
        });

    });

    function ValidatePassword()
    {
        var password = $("#password").val();
        var result;
        //Compares the length, if its not greater than MaximumLength
        if (password.length > @Model.MaximumLength) {
        return false;
        }

        //Compares the length, if its not shorter than MinimumLength
        if (password.length < @Model.MinimumLength) {
            return false;
        }

        var ind = '@Model.UserName'.toLowerCase().indexOf('@@');
        var symbolsRegEx = '@Model.Symbols.Replace(" ", "")';
        //Ensures if UserId/email is not in password
        if (@Model.UseUserIdInPassword.ToString().ToLower()) {
        var index = parseInt(ind, 10);
        var uname = '@Model.UserName'.toLowerCase().substring(0, index);
            if(password.indexOf(uname) > -1 )
            {
            return false;
            }
        }

        //Ensures User first or last name is not in password
        if (@Model.UseUserNameInPassword.ToString().ToLower()) {
            if(password.toLowerCase().indexOf('@Model.FirstName'.toLowerCase()) > 0 || password.toLowerCase().indexOf('@Model.LastName'.toLowerCase()) > 0)
            {
            return false;
            }
        }

        var successCounter = 0;
        //Ensures it contains lower case
        if (@Model.UseLowerCase.ToString().ToLower() ) {
            result = /[a-z]/.test(password);
            if (result) {
                successCounter++;
                }
        }
        //Ensures if contains UPPER case
        if (@Model.UseUpperCase.ToString().ToLower()) {
            result = /[A-Z]/.test(password);
            if (result) {
                successCounter++;
                }
        }
        //Ensures it has Symbols
        if (@Model.UseSymbols.ToString().ToLower()) {
            result = /[symbolsRegEx]/.test(password);
            if (result) {
                successCounter++;
                }
        }
        //Ensures it has numbers
        if (@Model.UseNumeric.ToString().ToLower()) {
            result = /\d/.test(password);
            if (result) {
                successCounter++;
                }
        }

        //Ensures if password contains least number of type required.
        if (@Model.NumberOfTypesRequiredInPassword > successCounter) {
        return false;
        }

        return result;

        }


</script>
<div id="pageHeader">
    <div id="pageTitle">
        <h2>
            Create New Password</h2>
    </div>
    <div id="userwelcome">
    </div>
    <div style="clear: both;">
    </div>
</div>
<div id="content" style="margin: 1em;">
    @using (Html.BeginForm("ResetPassword", "Login", FormMethod.Post, new { id = "myform" }))
    {
        @Html.ValidationSummary(true, "Please correct the errors and try again.")
        <div class="validation-summary-errors" id="errMsgPwdNoMatch" style="display: none;"><span>Please correct the errors and try again.</span>
        <ul><li>Passwords do not match. Please try again.</li>
        </ul></div>
        <div class="validation-summary-errors" id="errMsgPwdCriteria" style="display: none;"><span>Please correct the errors and try again.</span>
        <ul><li>Criteria is not fullfilled. Please try again.</li>
        </ul></div>
        <div id="resetpwd">
            <p>
                Create a new password before using Epi Info™ Web Enter.</p>
            <label for="newpass" style="display: block; font-weight: bold;">
                New Password:</label>
            @Html.PasswordFor(m => m.Password, new { id = "password", maxlength = 8, minlength = 6 })
            <label for="newpass" style="display: block; font-weight: bold;">
                Confirm Password:</label>
            @Html.PasswordFor(m => m.ConfirmPassword, new { id = "password_confirm", maxlength = 8, minlength = 6 })
            @Html.HiddenFor(m => m.UserName)
            @Html.HiddenFor(m => m.FirstName)
            @Html.HiddenFor(m => m.LastName)
            <p>
                <button type="submit" value="ResetPassword" class="default" id="ResetButton">
                    Submit</button>
                &nbsp;&nbsp;&nbsp;
                <button type="submit" value="Cancel" class="default" name="Action">
                    Cancel</button>
            </p>
        </div>
    
        <div id="pwdpolicy">
            <h3>
                Password Policy</h3>
            <ul style="margin: -11px 5px 5px 30px; padding: 0; line-height: 1.4em;">
                <li>Password must be @Model.MinimumLength to @Model.MaximumLength characters in length.</li>
                <li>Password may not contain your User ID or any part of your full name.</li>
                <li>Password must be created using @Model.NumberOfTypesRequiredInPassword of the following character types:</li>
                <ul style="margin: 1px 5px 5px 20px; padding: 0; line-height: 1.4em;">
                    <li>Upper case</li>
                    <li>Lower case</li>
                    <li>Numeric</li>
                    <li>Punctuation - <span>@Model.Symbols</span></li>
                </ul>
                
            </ul>
        </div>
        <div style="clear: both;">
        </div>
    }
</div>
